<template>
    <div>
       <h1>会员信息新增</h1>
       <table class="table">
        <thead>
            <tr>
                <td>姓名</td>
                <td>
                   <input type="text" v-model="data.name">
                </td>
            </tr>
             <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="data.pos">
                </td>
            </tr>
             <tr>
                <td>出生日期</td>
                <td>
                    <input type="date" v-model="data.birthDay">
                </td>
            </tr>
             <tr>
                <td>年龄</td>
                <td>
                    <input type="text" v-model="data.age">
                </td>
            </tr>
             <tr>
                <td>头像</td>
                <td>
                    <input type="file" @change="UpLoad">
                    <img :src="'https://localhost:7195'+data.img" style="width: 60px;height: 60px;">
                </td>
            </tr>
             <tr>
                <td>是否入职</td>
                <td>
                    <input type="checkbox" v-model="data.isDelete">选中为成功，不选中为不成功
                </td>
            </tr>
             <tr>
                <td>状态</td>
                <td>
                    <select v-model="data.startId">
                        <option value="0">请选择</option>
                        <option v-for="a in wert" :value="a.startId">{{a.name  }}</option>
                    </select>
                </td>
            </tr>
             <tr>
                <td>性别</td>
                <td>
                    <input type="radio" name="sex" id="" v-model="data.sex" value="1">男
                     <input type="radio" name="sex" id="" v-model="data.sex" value="2">女
                </td>
            </tr>
             <tr>
               
                <td colspan="2">
                    <input type="button" value="添加" @click="Add">
                </td>
            </tr>
        </thead>
       </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from "vue"
import axios from "axios";
const data=ref({
     "isDelete": true,
  "createId": 0,
  "createTime": "2025-06-08T11:37:09.470Z",
  "updateId": 0,
  "updateTime": "2025-06-08T11:37:09.470Z",
  "deleteId": 0,
  "deleteTime": "2025-06-08T11:37:09.470Z",
  "id": 0,
  "name": "",
  "pos": "",
  "birthDay": "2025-06-08T11:37:09.470Z",
  "age": 0,
  "img": "",
  "startId": 0,
  "sex": 0
})
onMounted(()=>{
    Xiala()
})
const wert=ref([{
 "startId": 1,
    "name": "出勤"
}])
const Xiala=()=>{
    axios.get("https://localhost:7195/api/User/Xiala").then(res=>{
        wert.value=res.data
    })
}
const Add=()=>{
    axios.post("https://localhost:7195/api/User/AddUser",data.value).then(res=>{
        if(res.data>0){
            alert('添加成功');
            location.href='/Showview';
        }
        else{
            alert('添加失败');
        }
    })
}
const UpLoad=(e:any)=>{
    var f=e.target.files[0]
    var fd=new FormData()
    fd.append("file",f)
    axios.post("https://localhost:7195/api/UpLoad/upload",fd).then(res=>{
         data.value.img=res.data
    })
}
</script>

<style scoped>

</style>